﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using ThreeByte.ActiveDeck.Service;
using System.Windows.Media;

namespace ThreeByte.ActiveDeck.AddIn.Config {
    public class PresentationGroup {

        protected static readonly XNamespace ns = ServiceConfiguration.NAMESPACE;

        public PresentationGroup() { }

        public PresentationGroup(int id, string name, Color color) {
            ID = id;
            Name = name;
            Color = color;
        }

        public int ID {
            get;
            set;
        }

        public string Name {
            get;
            set;
        }

        public Color Color {
            get;
            set;
        }

        public XElement ToXml() {
            XElement node = new XElement(ns + "UserGroups");
            node.Add(new XAttribute("ID", ID));
            node.Add(new XAttribute("Name", Name));
            node.Add(new XAttribute("Color", Color.ToString()));

            return node;
        }

        public static PresentationGroup FromXml(XElement node) {
            int id = int.Parse(node.Attribute("ID").Value);
            string name = node.Attribute("Name").Value;
            Color color = Colors.DeepPink;
            try {
                color = (Color)ColorConverter.ConvertFromString(node.Attribute("Color").Value);
            } catch (Exception) {

            }

            return new PresentationGroup(id, name, color);
        }
    }
}
